package znbkChangeCollection.ChangeCollectionPresenter;

import com.example.lancooznbk.presenter.presenter_interface.IBaseReviewPresenter;
import com.example.lancooznbk.view.base.ILoadPaperView;
import com.lancoo.reviewsystem.utils.ToastUtils;
import com.lancoo.rxretrofitlibrary.Api.UserInfo;
import com.lancoo.rxretrofitlibrary.http.HttpManager;
import com.lancoo.rxretrofitlibrary.listener.HttpOnNextListener;

import znbkChangeCollection.ChangeCollectionApi.ChangeCollectionApi;
import znbkChangeCollection.ChangeCollectionEntityModel;
import znbkListSc.ZnbkPaperScInfor;
import znbkListSc.activity.CollectionListActivity;
import znbkTestPaperCtfd.activity.WrongTopicTutoringPaperActivity;
import znbkTestPaperInfor.ZnbkPaperDef;
import znbkTestPaperInfor.ZnbkPaperInfor;
import znbkTestPaperLstjt.activity.HistoryRecommendQuesPaperActivity;
import znbkTestPaperNtxl.activity.TrainingDifficultProblemsPaperActivity;
import znbkTestPaperRdqh.activity.WeekAscensionPaperActivity;
import znbkTestPaperRdtz.activity.HeatPointExtensionPaperActivity;
import znbkTestPaperRdtz.activity.HeatPointExtensionPaperSplActivity;
import znbkTestPaperXtfx.activity.SystemReviewPaperActivity;

import static znbkTestPaperRdtz.activity.HeatPointExtensionPaperActivity.mEntityRdtz;

/**
 * Created by Administrator on 2018\2\23 0023.
 */

public class ChangeCollectionPresenter implements IBaseReviewPresenter {

    private ILoadPaperView view;
    private int ModelFrom;
    private boolean isFromExit = false;


    public ChangeCollectionPresenter(ILoadPaperView view, int modelFrom) {
        this.view = (ILoadPaperView) view;
        this.ModelFrom = modelFrom;
    }

    @Override
    public void getData(boolean isShowLoading) {
        //  if (isShowLoading) view.showLoading();
        HttpOnNextListener<String> httpOnNextListener = new HttpOnNextListener<String>() {


            @Override
            public void onNext(String s) {
                if(s.equals("true")){
                    //操作成功
//                    ToastUtils.showShort("操作成功");
                }else{
                    ToastUtils.showShort("收藏失败"+s.toString());
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
            }
        };

        ChangeCollectionApi api = null;
        if(ModelFrom == ZnbkPaperDef.FROM_COLLECTION) {
            api = new ChangeCollectionApi(httpOnNextListener, (CollectionListActivity) view);
        }else if(ModelFrom==ZnbkPaperDef.FROM_TRAINING_DIFFICULT_PROBLEMS){
            api = new ChangeCollectionApi(httpOnNextListener, (TrainingDifficultProblemsPaperActivity) view);
        }else if(ModelFrom==ZnbkPaperDef.FROM_WEEK_ASCENSION){
            api = new ChangeCollectionApi(httpOnNextListener, (WeekAscensionPaperActivity) view);
        }else if(ModelFrom==ZnbkPaperDef.FROM_SYSTEM_REVIEW){
            api = new ChangeCollectionApi(httpOnNextListener, (SystemReviewPaperActivity) view);
        }else if(ModelFrom==ZnbkPaperDef.FROM_WRONG_TOPIC_TUTORING){
            api = new ChangeCollectionApi(httpOnNextListener, (WrongTopicTutoringPaperActivity) view);
        }else if(ModelFrom==ZnbkPaperDef.FROM_HISTORY_RECOMMEND_QUESTION){
            api = new ChangeCollectionApi(httpOnNextListener, (HistoryRecommendQuesPaperActivity) view);
        }else if(ModelFrom==ZnbkPaperDef.FROM_HEAT_POINT_EXTENSION){
            api = new ChangeCollectionApi(httpOnNextListener, (HeatPointExtensionPaperActivity) view);
        }else if(ModelFrom==ZnbkPaperDef.FROM_HEAT_POINT_EXTENSION_SPL){
            api = new ChangeCollectionApi(httpOnNextListener, (HeatPointExtensionPaperSplActivity) view);
        }

        api.setmChangeCollectionEntityModel(ZnbkPaperScInfor.changeCollectionEntityModel);
        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(api);
    }

    @Override
    public void getMoreData() {
        getData(false);
    }

    @Override
    public void getDataByStatus(int position) {
        getData(false);
    }

    public void getData(boolean isShowing ,boolean isFromExit){
        this.isFromExit = isFromExit;
        getData(isShowing);
    }

}